import java.io.IOException;
import java.net.*;

public class Test2 {
    public static void main(String[] args) throws IOException, InterruptedException {
        Thread.sleep(1000);
        //创建DatagramSocket对象
        DatagramSocket socket = new DatagramSocket();
        for (int i = 0; i < 100; i++) {
            //发送数据
            String message = i + "";
            byte[] data = message.getBytes();
            InetAddress address = InetAddress.getByName("127.0.0.1");
            int port = 8080;
            //创建DatagramPacket对象
            DatagramPacket packet = new DatagramPacket(data, data.length, address, port);
            //发送数据
            socket.send(packet);
            System.out.println("发送数据成功");
            //发送延迟
            Thread.sleep(100);
        }
        //关闭DatagramSocket对象
        socket.close();
    }
}
